package com.eagleyng.utils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

public class FileUtils {
	
	
	public static void inputstreamToFile(FileInputStream ins, File file) throws Exception {
		OutputStream os = new FileOutputStream(file);
		int bytesRead = 0;
		byte[] buffer = new byte[8192];
		while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
			os.write(buffer, 0, bytesRead);
		}
		os.close();
		ins.close();
	}
	
	public static void inputstreamToMFile(FileInputStream ins, String filePath,int byteSize) throws Exception {
		int bytesRead = 0;
		byte[] buffer = new byte[byteSize];
		int count = 0;
		while ((bytesRead = ins.read(buffer, 0, byteSize)) != -1) {
			System.out.println("================================"+count);
			OutputStream os = new FileOutputStream(new File(filePath+"."+count));
			os.write(buffer, 0, bytesRead);
			os.close();
			count ++;
		}
		
		ins.close();
	}
	
	public static void main (String[] arg){
		 FileInputStream fis;
		try {
			fis = new FileInputStream("C:/Users/eagleyng/Desktop/ceshi/metrosh.db");
			FileUtils.inputstreamToMFile(fis, "C:/Users/eagleyng/Desktop/ceshi/metrosh.db", 1000000);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("2222222222");
	}
	
}
